package com.vunguyen.controller;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.vunguyen.service.UserService;


@Controller
public class UserController {
	
	@Autowired
	private UserService userService;	
	
	@RequestMapping(value = "/trangchu", method = RequestMethod.GET)
	public String TrangChu()
	{
		return "trangchu";
	}

	
	@RequestMapping(value = "/login", method = RequestMethod.POST)
	public String Login(HttpServletRequest request, HttpServletResponse response)
	{
		int username = Integer.parseInt(request.getParameter("username"));
		String password = request.getParameter("password");
		int quyen = userService.getQuyenDangNhap(username);
		
		if(userService.checkLogin(username, password))
		{
			request.getSession().setAttribute("username", username);
			request.getSession().setAttribute("password", password);
			request.getSession().setAttribute("quyen", quyen);
			return userService.getPhanQuyen(username);
		}
		else{
			return "trangchu";
		}


		
	}
	

}
